#include <cv.h>
#include <highgui.h>

#include "HandInterface.hpp"
#include "TrackDataServer.hpp"

#include <boost/thread.hpp>

using namespace cv;
using namespace hi;

void AbstractTrackerRunner::init() {
//	HiVisualiser::addWindow("handtracker");
//	HiVisualiser::moveWindow("handtracker",500,200);
	
	
	Ptr<ResourceTracker> rt = new ResourceTracker( "../config/runtimeSettings/cfg.xml" );
	rt->loadCategory("TestData");
	
	
	//capPtr = rt->getFileVideoCapture( "loS1Rasmus2v1" );
	//capPtr = rt->getFileVideoCapture( "loS1Ellen1v1" );
	//capPtr = rt->getFileVideoCapture( "loS1Ellen1v2" );
	//capPtr = rt->getFileVideoCapture( "loS1Ellen1v3" );
	capPtr = rt->getFileVideoCapture( "loS1Sara1v1" );
	
//TODO REENABLE	
//	
//	capPtr = Ptr< VideoCapture >(new VideoCapture(0)); // open the default camera
//	bool captureSizeSet = capPtr->set( CV_CAP_PROP_FRAME_WIDTH , 640 );
//	captureSizeSet &= capPtr->set( CV_CAP_PROP_FRAME_HEIGHT , 480 );
//	if(!capPtr->isOpened() || !captureSizeSet) { // check if we succeeded
//		CV_Error( CV_StsError, "Unable to set correct camera frame size (640x480)!"); //throws exception!
//	}
}

// -- protected methods -- //
void AbstractTrackerRunner::setNextFrame() {
	prevFrame = frame;
	(*capPtr) >> frame;
	flip(frame, frame, 1);
}

void AbstractTrackerRunner::presetNextFrame() {
	(*capPtr) >> nextFrame;
	flip(nextFrame, nextFrame, 1);
}

void AbstractTrackerRunner::loadNextFrame() {
	prevFrame = frame;
	frame = nextFrame;
}


